{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "95db2669",
   "metadata": {},
   "source": [
    "## Flask入门学习-Week1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "efb61d12",
   "metadata": {},
   "outputs": [],
   "source": [
    "from flask import Flask\n",
    "\n",
    "app = Flask(__name__)\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return 'Hello everyone,this is my first flask app'\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d97b6ebb",
   "metadata": {},
   "source": [
    "当我们在命令行运行：flask run 而没有具体地指定应用程序文件时，flask会默认运行app.py\n",
    "可以看到我们实际在hello.py文件中编写应用程序，因此当前目录不存在这样的文件，程序会报错：\n",
    "Error: Could not locate a Flask application. Use the 'flask --app' option, 'FLASK_APP' environment variable, or a 'wsgi.py' or 'app.py' file in the current directory.\n",
    "\n",
    "我们有两种解决方案：\n",
    "- 设置环境变量\n",
    "- 在运行程序时指定具体的文件\n",
    "\n",
    "对于不同的终端系统：上面的命令不尽相同。\n",
    "\n",
    "下面是我在windows下PowerShell环境下的一些命令和对应的错误信息：\n",
    "![错误信息](../img/errorMessage1.png)\n",
    "\n",
    "**管理环境变量：** python-dotenv\n",
    ".flaskenv 用来存储 Flask 命令行系统相关的公开环境变量；而 .env 则用来存储敏感数据，不应该提交进 Git 仓库，我们把文件名 .env 添加到 .gitignore 文件的结尾（新建一行）来让 Git 忽略它。\n",
    "\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "python_web",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
